<template>
	<view class="content">
		<!-- header -->
		<view class="header">
			<view class="header-box">
				<view class="header-box-search" @click="goNav('/pages/index/search/index')">
					<u-icon name="search" color="#666666" size="36"></u-icon>
					<text>搜索你需要的服务</text>
				</view>
			</view>
		</view>
		<view class="menu" v-if="tabsList.length!=0">
			<!-- 左侧菜单 -->
			<view class="menuLeft">
				<scroll-view scroll-y="true" class="menuLeft-scroll">
					<view :class="current==-1?'active':''" @click="qeihuan(-1)" class="menuLeft-scroll-item">
						热门服务
					</view>
					<view :class="current==index?'active':''" @click="qeihuan(index,item)" class="menuLeft-scroll-item"
						v-for="(item,index) in tabsList" :key="index" v-if="item.children.length > 0">
						{{item.gameName}}
					</view>
				</scroll-view>
			</view>
			<!-- 右侧内容 -->
			<view class="menuRight">
				<!-- <view class="menuRight-search">
					<rendropdownfilters :filterData='filterData' :border="false" :defaultIndex='defaultIndex'
						@onSelected='change' class="u-skeleton-rect">
					</rendropdownfilters>
				</view> -->
				<scroll-view scroll-y="true" class="menuRight-scroll" @scrolltolower="reachbottom">
					<view class="menuRight-scroll-item">
						<view class="flex align-center justify-between padding-lr-sm" @click="rmGoDetails()"
							v-if="current == -1">
							<view class="titbox">热门服务</view>
							<view style="color: #666666;">更多
								<image src="../../static/images/my/right.png"
									style="width: 12upx;height: 22upx;margin-left: 10upx;"></image>
							</view>
						</view>
						<view class="flex align-center justify-between padding-lr-sm" @click="goDetail()"
							v-if="current != -1 && tabsList[current].gameName">
							<view class="titbox">{{tabsList[current].gameName}}</view>
							<view style="color: #666666;">更多
								<image src="../../static/images/my/right.png"
									style="width: 12upx;height: 22upx;margin-left: 10upx;"></image>
							</view>
						</view>

						<view class="flex flex-wrap" v-if="current == -1">
							<view class="text-center margin-left-sm margin-top" v-for="(item,index) in rmErList"
								@click="rmGoDetails(item.id)">
								<image :src="item.gameImg?item.gameImg:'../../static/logo.png'" mode=""
									style="width: 152rpx;height: 152rpx;"></image>
								<view class="text-sm">{{item.gameName}}</view>
							</view>
						</view>
						<view class="flex flex-wrap" v-else>
							<view class="text-center margin-left-sm margin-top" v-for="(item,index) in tabsListRight"
								@click="goDetails(item.id)">
								<image :src="item.gameImg?item.gameImg:'../../static/logo.png'" mode=""
									style="width: 152rpx;height: 152rpx;"></image>
								<view class="text-sm">{{item.gameName}}</view>
							</view>
						</view>

					</view>
					<!-- <u-loadmore v-if="tabsListRight.length==10" :status="status" :loadmoreText="loadingText"
						:loadingText="loadmoreText" :nomoreText="nomoreText" /> -->
					<empty v-if="tabsListRight.length == 0"></empty>
				</scroll-view>
			</view>
		</view>

		<u-tabbar :list="tabbarList" :mid-button="true" bg-color="#FFFFFF" active-color="#557EFD"
			inactive-color="#999999">
		</u-tabbar>
	</view>
</template>

<script>
	import rendropdownfilters from '../../components/ren-dropdown-filters/ren-dropdown-filter.vue'
	import empty from '../../components/empty.vue'
	export default {
		components: {
			rendropdownfilters,
			empty
		},
		data() {
			return {
				status: 'loadmore',
				loadingText: '努力加载中',
				loadmoreText: '轻轻上拉',
				nomoreText: '实在没有了',
				current: -1,
				isVip: false,
				defaultIndex: [0, 0, 0],
				filterData: [
					[{
							label: '智能优选',
							value: '',
						},
						{
							label: '距离优先',
							value: 3,
						},
						{
							label: '人气优先',
							value: 2,
						},
						{
							label: '同城',
							value: 1,
						}
					],
					[{
							label: '销量',
							value: '',
						},
						{
							label: '从高到低',
							value: 'desc',
						},
						{
							label: '从低到高',
							value: 'asc',
						}
					],
					[{
							label: '价格',
							value: '',
						},
						{
							label: '从高到低',
							value: 'desc',
						},
						{
							label: '从低到高',
							value: 'asc',
						}
					],
				],
				tabsList: [],
				tabsListRight: [],
				idHome: '',
				token: '',
				page: 1,
				limit: 10,
				gameName: '',
				value1: '',
				value2: '',
				value3: '',
				userId: '',
				parentId: '',
				rmErList: [],
				tabbarList: this.$store.state.list,
			}
		},
		onLoad() {
			this.getClassfly();

		},
		onShow() {
			let _this = this
			_this.token = uni.getStorageSync('token')
			_this.userId = uni.getStorageSync('userId') ? uni.getStorageSync('userId') : ''
			if (uni.getStorageSync('token')) {

				_this.getIsVip()
			}
			this.getQueryEjGameSort();
		},
		methods: {
			/**
			 * 获取二级分类排序列表
			 */
			getQueryEjGameSort() {
				this.$Request.get('/app/appGame/queryEjGameSort').then(res => {
					this.rmErList = res.data;
				})
			},
			goDetail() {
				uni.navigateTo({
					url: '/pages/index/game/myOrder?name=' + this.tabsList[this.current].gameName + '&parentId=' +
						this.tabsList[this.current].id
				})
			},
			// 热门服务跳转
			rmGoDetails(id) {
				if(id){
					uni.navigateTo({
						url: '/pages/index/game/myOrder?name=热门服务&isRm=true'+'&classparentId=' + id
					})
				}else{
					uni.navigateTo({
						url: '/pages/index/game/myOrder?name=热门服务&isRm=true'
					})
				}
				
			},
			goDetails(id) {
				uni.navigateTo({
					url: '/pages/index/game/myOrder?name=' + this.tabsList[this.current].gameName + '&parentId=' +
						this.tabsList[this.current].id + '&classparentId=' + id
				})
			},
			getIsVip() {
				this.$Request.get("/app/UserVip/isUserVip").then(res => {
					if (res.code == 0) {
						this.isVip = res.data
						uni.setStorageSync('isVIP', res.data)
					}
				});
			},
			//跳转至搜索
			goNav(url) {
				uni.navigateTo({
					url
				})
			},
			//触底
			reachbottom() {
				// uni.showToast({
				// 	title: '已经触底了',
				// 	icon: 'none'
				// })
				//若页面数据等于10则加载下一页
				if (this.tabsListRight.length == 10) {
					this.page += 1
					this.status = 'loading'
					// this.getLists( 2)
				} else if (this.tabsListRight.length < 10) {
					this.status = 'nomore'
				}
			},
			// 跳转订单
			goOrder(id) {
				if (this.token) {
					uni.navigateTo({
						url: '/pages/index/game/order?id=' + id
					});
				} else {
					uni.navigateTo({
						url: '/pages/public/login'
					});
				}
			},
			// 获取类型
			getClassfly() {
				let _this = this
				this.$Request.get("/app/appGame/queryGameName?parentId=0").then(res => {
					if (res.code == 0) {
						console.log(res.data, '11111111111111111')
						_this.tabsList = res.data
						_this.gameName = res.data[0].gameName
						_this.parentId = res.data[0].parentId
						// _this.idHome
						// _this.getLists( 1)
						_this.tabsListRight = _this.tabsList[0].children
					}
				});
			},
			//根据类型获取商品 已废弃
			getLists(type) {
				let data = {
					id: this.gameName,
					page: this.page,
					limit: this.limit,
					condition: this.value1, //智能优选
					salesNum: this.value2, //不限销量
					by: this.value3, //价格
					latitude: uni.getStorageSync('latitude'),
					longitude: uni.getStorageSync('longitude'),
					city: uni.getStorageSync('city'),
					parentId: this.parentId
				}
				let _this = this
				this.$Request.get("/app/orderTaking/queryTakings", data).then(res => {
					if (res.code == 0) {
						uni.hideLoading()
						console.log(res.data.list, '222222222')
						if (type == 1) {
							_this.tabsListRight = res.data.list
						} else {
							_this.tabsListRight = [..._this.tabsListRight, ...res.data.list]
						}
					}
				});
			},
			// 左侧筛选
			qeihuan(index, item) {
				// uni.showLoading({
				// 	title:'加载中'
				// })
				this.current = index
				// this.page = 1

				if (index != -1) {
					this.tabsListRight = this.tabsList[index].children
				}


				// this.gameName = item.gameName
				// this.parentId = item.parentId
				// this.getLists( 1)


			},
			// 筛选
			change(e) {
				// console.log(e[0][0], '+++++++++')
				// console.log(e,'888888888888888888888888')
				this.page = 1
				this.value1 = e[0][0].value
				this.value2 = e[1][0].value
				this.value3 = e[2][0].value


				// this.getLists( 1)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		// height: calc(100vh - 88rpx);
		height: 100vh;
		background-color: #F7F7F7;
	}

	.header {
		width: 100%;
		height: 88rpx;
		background-color: #ffffff;
		display: flex;
		justify-content: center;
		align-items: center;
		position: fixed;
		/* #ifdef H5 */
		top: 0rpx;
		/* #endif */
		/* #ifndef H5 */
		top: 0;
		/* #endif */
		z-index: 99;

		.header-box {
			width: 686rpx;
			height: 60rpx;

			.header-box-search {
				width: 100%;
				height: 100%;
				background-color: rgb(247, 247, 247);
				border-radius: 10rpx;
				display: flex;
				align-items: center;
				padding-left: 30rpx;

				text {
					margin-left: 20rpx;
					font-size: 24rpx;
					color: #666666;
				}
			}
		}
	}

	.active {
		font-weight: bold !important;
		background-color: #F7F7F7;
		color: #557EFD !important;
		font-family: PingFang-SC-Bold !important;
		font-size: 32upx !important;
	}

	.menu {
		width: 100%;
		height: calc(100vh - 88rpx);
		display: flex;
		margin-top: 90upx;

		.menuLeft {
			// width: 220rpx;
			width: 30%;
			height: 100%;

			.menuLeft-scroll {
				width: 100%;
				height: 100%;
				background-color: #ffffff;
			}

			.menuLeft-scroll-item {
				width: 100%;
				height: 92rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				color: #333333;
				font-size: 28rpx;
				font-weight: 500;
			}
		}

		.menuRight {
			// width: 530rpx;
			width: 70%;
			height: 100%;
			position: relative;

			// background-color: yellow;
			.menuRight-search {
				width: 100%;
				height: 92rpx;
				position: absolute;
				top: 0;
			}

			.menuRight-scroll {
				width: 100%;
				height: calc(100% - 92rpx);
				position: absolute;
				top: 30rpx;

				.menuRight-scroll-item {
					width: 100%;
					height: 240rpx;
					// display: flex;
					// justify-content: center;
					// flex-wrap: wrap;
					// margin-bottom: 20rpx;

					.menuRight-scroll-item-box {
						width: 90%;
						height: 100%;
						background-color: #ffffff;
						border-radius: 8rpx;
						display: flex;

						align-items: center;

						.menuRight-scroll-item-box-l {
							width: 200rpx;
							height: 200rpx;
							margin-left: 21rpx;

							image {
								width: 100%;
								height: 100%;
							}
						}

						.menuRight-scroll-item-box-r {
							width: calc(100% - 237rpx);
							height: 200rpx;
							margin-left: 16rpx;
							display: flex;
							flex-wrap: wrap;

							view {
								// margin-top: 16rpx;
								width: 100%;
							}

							view:nth-of-type(1) {
								color: #1E1F31;
								font-size: 28rpx;
								font-weight: bold;
							}

							view:nth-of-type(2) {
								color: #999999;
								font-size: 24rpx;
								font-weight: 400;
							}

							view:nth-of-type(3) {
								color: #999999;
								font-size: 20rpx;
								font-weight: 400;
							}

							view:nth-of-type(4) {
								margin-top: 15rpx;
								color: #FF1200;
								font-weight: 800;

								span:nth-of-type(1) {
									font-size: 24rpx;
								}

								span:nth-of-type(2) {
									font-size: 32rpx;
								}

								span:nth-of-type(3) {
									font-size: 24rpx;
								}
							}
						}
					}
				}
			}
		}
	}

	.filter-wrapper {
		width: auto !important;
	}

	.navs {
		background-color: #F7F7F7 !important;
	}

	.titbox {
		background: #FFFFFF;
		color: #333333;
		padding: 10rpx 30rpx;
		border-radius: 10rpx;
	}
</style>